package com.taha.mail.util;

/**
 * @author Zahra Ezati
 *
 */

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

import com.taha.mail.entity.UserBean;

public class TahaDBSqlConnection {

	private static String dbLocation = "Taha";
    private static String dbURL = "jdbc:derby://localhost:1527/";
    private static Connection conn = null;
    private static String driverName = "org.apache.derby.jdbc.ClientDriver";
  
    
    public static Connection getConnInstance()
    {
    	if (conn == null)
    	{

    		conn = createConnection("app","919");
    	}
    	return conn;
    }
    
    private static Connection createConnection(String userName, String password)
    {
        try
        {
            Class.forName(driverName);
            Properties dbProps = new Properties();
            dbProps.put("user", userName);
            dbProps.put("password", password);
            conn = DriverManager.getConnection(dbURL + dbLocation, dbProps);
            System.out.println("Connection successful!");
        }
        catch (Exception except)
        {
            System.out.print("Could not connect to the database with username: " + userName);
            System.out.println(" password " + password);
            System.out.println("Check that the Derby Network Server is running on localhost.");
            except.printStackTrace();
        }
        return conn;
    }
       
}

